class Solution(object):
    def finalPrices(self, prices):
        st = [0]
        out = prices.copy()
        for index, p in enumerate(prices[1:]):
            while st and p <= prices[st[-1]]:
                node = st.pop()
                out[node] = prices[node] - p
            st.append(index + 1)
        return out